const http=require("../../utils/http")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        banner:{},
        posts:{},
        lastid:0
    },
    jump(){
        wx.navigateTo({
          url: "/pages/search/search",
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.showLoading({
            title: '加载中...',
          })
        http.get('/index/index').then(
            res=>{
                wx.hideLoading()
                // console.log(res);
                this.setData({
                    banner:res.banner,
                    posts:res.posts,
                    lastid:res.posts.lastid
                })
            }
        )
        // console.log(this.data.banner);
    },
  

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        wx.showLoading({
          title: '加载中...',
        })
        http.get('/index/getIndexPosts/lastid/'+this.data.lastid).then(
           
            res=>{
                wx.hideLoading()
                // console.log(res);
                let lists = res.list
                let posts = this.data.posts
                let moreLists = posts.list.concat(lists)
                posts.list = moreLists
               this.setData({
                   posts:posts,
                   lastid:res.lastid
               })
            }
        )
    },
    onPullDownRefresh: function () {
        wx.showLoading({
          title: '加载中...',
        })
        http.get('/index/getIndexPosts/lastid/'+this.data.lastid).then(
            res=>{
                wx.hideLoading()
                // console.log(res);
                let lists = res.list
                let posts = this.data.posts
                let moreLists =lists.concat( posts.list)
                posts.list = moreLists
               this.setData({
                   posts:posts,
                   lastid:res.lastid
               })
            }
        )
     },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})